
      //电话过滤器
	   app.filter('telDetail',function(){
        //返回一个函数
        return function(value){
            return value.substr(0,3)+'····'+value.substr(7,4);
        }
    });
   
app.controller('comDetailCtrl', function($scope,$http,$routeParams) {
	           $scope.CDid = $routeParams.id;
	          $scope.num=1;
	          
	      //根据传值检索数据库
	       $http.get('../php/g_comDetail.php?id='+$scope.CDid).success(function(data1){
    	      	 	       $scope.gooseDe=data1;
    	      	 	        console.log( $scope.gooseDe)
    	      	 	         var arr=[]; 
    	      	 	        var obj1 = {
    	      	 	        	    shangjia:$scope.gooseDe[0].shops,
    	      	 	        	   name:$scope.gooseDe[0].name,
    	      	 	        	   guige:$scope.gooseDe[0].guige,
    	      	 	        	   danjia:$scope.gooseDe[0].price,
    	      	 	        	   num: $scope.num,
    	      	 	        	   image:$scope.gooseDe[0].image,
    	      	 	        }
    	      	 	         arr.push(obj1);
    	      	 	       var gooseAA=JSON.stringify(arr)
    	      	 	       localStorage.setItem('gouwu1',gooseAA);
    	      	 }) 
	           
	           
	           
	           
	           
	
   
	 //显示隐藏商品介绍
	  $scope.bol=true;
	  $scope.detailFun1=function(e){
	  	$scope.bol=!$scope.bol
	  	$('.g_comdetailEval span').removeClass('g_comdetailEvalAt')
	  	$(e.target).addClass('g_comdetailEvalAt')
	  }
	  //商品评价数据调取
	   $scope.comDdata=[{ 
	       userImg:'../img/ggh/jifenDetail/photo.png',
	       userTel:'15103785516',
	       score:3,
	       com:'帮同事买的 灰常给力',
	       time:'2017.05.06'
	   },{
	   	   userImg:'../img/ggh/jifenDetail/photo.png',
	       userTel:'15103785517',
	       score:4,
	       com:'好吃好吃正好吃',
	       time:'2017.05.01'
	   }]
	       //评价之星级
	      $scope.fun = function(a,b){
	      	var m = $scope.comDdata[a].score;
	      	if(b<m){
	      		return 'g_comdetailIntroaa'
	      	}	
	      } 
	  //收藏店铺图标切换
	  $scope.bol1=true;
	   $('.g_comdetailGose_R4Ft1_1').on('click',function(){
	   	if( $scope.bol1==true){
	   		$('.g_comdetailGose_R4Ft1_1').css('background','url(../img/f_myaccount/hong.png)no-repeat left')
	   		 $scope.bol1=false;
	   	}else{
	   		$('.g_comdetailGose_R4Ft1_1').css('background','url(../img/f_myaccount/hui.png) no-repeat left')
	   		  $scope.bol1=true;
	   	} 
	   	//收藏店铺入数据库
//	   	  $http.get('../php/g_comDetail.php?id='+ $scope.CDid).success(function(data){
//	   	  	console.log(data)
//	   	  })
	   	
	   }) 
	
    //放大镜
	$('.zoom').on('mouseenter', function(e) {
		$('.zoomL').show();
		$('.zoomB').show();
		var even = e || event;

		$('.zoom').on('mousemove', function(e) {
			var even = e || event;
			var lWidth = $('.zoomL').width();
			var lHeight = $('.zoomL').height();
			var imgWidth = $('.zoom img').width()
			var imgHeight = $('.zoom img').height();
			//获取移动框位置
			console.log(even.clientY)
			var x1 = even.pageX - $('.zoom').offset().left - 0.5 * lWidth
			var y1 = even.pageY - $('.zoom').offset().top - 0.5 * lHeight
				//限定移动框范围
			x1 <= 0 ? x1 = 0 : x1 = x1;
			x1 > (imgWidth - lWidth) ? x1 = (imgWidth - lWidth) : x1 = x1;
			y1 <= 0 ? y1 = 0 : y1 = y1;
			y1 > (imgHeight - lHeight) ? y1 = (imgHeight - lHeight) : y1 = y1;
			$('.zoomL').css({
				left: x1,
				top: y1
			})
			var zoomBW = $('.zoomB').width();
			var zoomBH = $('.zoomB').height();
			var zoomBImgW = $('.zoomB img').width();
			var zoomBImgH = $('.zoomB img').height();
			var x2 = x1 * (zoomBImgW - zoomBW) / (imgWidth - lWidth)
			var y2 = y1 * (zoomBImgH - zoomBH) / (imgHeight - lHeight)
			$('.zoomB')[0].scrollLeft = x2;
			$('.zoomB')[0].scrollTop = y2;

		})

	})
	$('.zoom').on('mouseleave', function() {
		$('.zoomL').hide();
		$('.zoomB').hide();
	})

	//商品图片预览
	$('.g_comdetailGose_Limg img').each(function(i, e) {

		$(e).on('click', function() {
			var imgUrl = $(e).attr('src');
			$('.g_comdetailMT img').eq(0).attr('src', imgUrl)
			$('.g_comdetailMT').show();
		})
	})
	$('.g_comdetailMT img').eq(1).on('click', function() {
		$('.g_comdetailMT').hide();
	})

    //规格味道选择
    $('.g_comdetailGose_RFt4').each(function(index,el){
    	    $(el).on('click',function(){
    	    	if(index<3){
    	    		 $('.g_comdetailGose_RFt4').eq(0).removeClass('g_comdetailAt')
    	    		 $('.g_comdetailGose_RFt4').eq(1).removeClass('g_comdetailAt')
    	    		 $('.g_comdetailGose_RFt4').eq(2).removeClass('g_comdetailAt')
      	    $(this).addClass('g_comdetailAt')
      	    
      	    
    	    	}else{
    	    		$('.g_comdetailGose_RFt4').eq(3).removeClass('g_comdetailAt')
    	    		 $('.g_comdetailGose_RFt4').eq(4).removeClass('g_comdetailAt')
    	    		 $('.g_comdetailGose_RFt4').eq(5).removeClass('g_comdetailAt')
      	    $(this).addClass('g_comdetailAt')
    	    		
    	    	}
      	 
        })
    })
    
    //立即购买存入数据到本地
    $('.g_comdetailB').on('click',function(){
    	       localStorage.setItem('guige',$('.g_comdetailGose_R3_2 .g_comdetailAt').html())//规格
    	       localStorage.setItem('countNum',$scope.detailCount)//数量
    	       //商家
//  	       localStorage.setItem('shangjia',$scope.detailCount)
//  	       //物品名称
//  	       localStorage.setItem('name',$scope.detailCount)
//  	       //图片地址
//  	       localStorage.setItem('src',$scope.detailCount)
//  	       //单价
//  	       localStorage.setItem('danjia',$scope.detailCount)
//  	       //id
//  	       localStorage.setItem('id',$scope.detailCount)
    })
    //加入购物车存入数据库
    $('.g_comdetailA').on('click',function(){
//   var shangjia =   
//   var src = 
//   var name = 
//   var guige = $('.g_comdetailGose_R3_2 .g_comdetailAt').html();
//   var danjia = 
//   var num = $scope.detailCount
//   var id = 
//   $http.get('../php/gouwuche.php?shangjia'+shangjia+'&src='+src+'&name='+name+'&guige='+guige+'&danjia'+danjia+'&num'+num+'&id'+id).success(function(){})
   })
})